package norbert.controls {
	/* IMPORTS */

	import mx.controls.TextInput;
	import flash.events.MouseEvent;
	import flash.events.FocusEvent;

	public class EditableText extends TextInput {
		/* CONSTRUCTOR */
		
		public function EditableText() {
			setStyle("backgroundAlpha", 0);
			setStyle("borderStyle", "none");
			addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
			addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
			addEventListener(FocusEvent.FOCUS_IN, onFocusIn);
			addEventListener(FocusEvent.FOCUS_OUT, onFocusOut);
		}

		/* EVENT HANDLERS */
		
		private var mouseIn: Boolean;
		private function onMouseOver(event: MouseEvent): void {
			mouseIn = true;
			setStyle("backgroundAlpha", 1);
		}
		private function onMouseOut(event: MouseEvent): void {
			mouseIn = false;
			if (focusManager.getFocus() != this) {
				setStyle("backgroundAlpha", 0);
			}
		}

		private function onFocusIn(event: FocusEvent): void {
			setStyle("backgroundAlpha", 1);
		}
		private function onFocusOut(event: FocusEvent): void {
			if (!mouseIn) {
				setStyle("backgroundAlpha", 0);
			}
		}
	}
}
